#ifndef LOGMANAGER_H
#define LOGMANAGER_H

#include <QObject>
#include <QFile>
#include <QTextStream>
#include <QMutex>
#include <QDateTime>
#include <QDir>

class LogManager : public QObject
{
    Q_OBJECT

public:
    static LogManager& ins();

    void initialize(const QString& logDir = "logs");

    static void log(QtMsgType type, const QString &msg);

private:
    void handleMessage(QtMsgType type, const QString &msg);

    void openLogFile(QFile& file, const QString& filePath);

    void writeToFile(QFile& file, const QString& message);

private:
    QMutex mutex_;
    QFile debugFile_;
    QFile infoFile_;
    QFile warningFile_;
    QFile errorFile_;

    LogManager() = default;
    ~LogManager() {
        debugFile_.close();
        infoFile_.close();
        warningFile_.close();
        errorFile_.close();
    }
};

#endif // LOGMANAGER_H
